package com.eastmoney.emis.edda.domain.entity;

import com.eastmoney.emis.edda.common.Constants;
import com.eastmoney.emis.edda.domain.valueobject.EddaApplyStatus;
import com.eastmoney.emis.edda.domain.valueobject.MandateStatus;
import com.eastmoney.emis.edda.infrastructure.edda.po.EmhkEddaApplyPo;
import org.springframework.util.ObjectUtils;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * @description: Description
 * @projectName: EDDA-HSBC
 * @package: com.eastmoney.emis.edda.domain.entity
 * @author: 汪程程
 * @date: 2022/9/30 1:50 PM
 * @version: 1.0
 */
public class EddaApply {

    private String eid;
    private String status;
    private String clientId;
    private String bankCode;
    private String bankAccount;
    private String customEngName;
    private String registerId;
    private String mandateId;
    private LocalDate grantStartDate;
    private LocalDate grantExpiryDate;
    private String creditReference;
    private String mobile;
    private String debtorId;
    private String debtorSchemeName;
    private String currency;
    private String maximumAmount;
    private String frequencyType;
    private String otpNumber;
    private String language;
    private String note;

    private LocalDateTime createdTime;
    private LocalDateTime updatedTime;
    private String rejectReasonCode;


    public EddaApply() {
    }

    public EddaApply(EmhkEddaApplyPo emhkEddaApplyPo) {
        this.eid = emhkEddaApplyPo.EID;
        this.status = emhkEddaApplyPo.STATUS;
        this.clientId = emhkEddaApplyPo.HKCUACCID;
        this.bankCode = emhkEddaApplyPo.BANKCODE;
        this.bankAccount = emhkEddaApplyPo.BANKACCOUNT;
        this.customEngName = emhkEddaApplyPo.CUSTENGNAME;
        this.registerId = emhkEddaApplyPo.REGISTID;
        this.mandateId = emhkEddaApplyPo.MANDATEID;
        this.grantStartDate = emhkEddaApplyPo.GRANTSTARTDATE;
        this.grantExpiryDate = emhkEddaApplyPo.GRANTEXPIRYDATE;
        this.creditReference = emhkEddaApplyPo.CREDITREFERENCE;
        this.mobile = emhkEddaApplyPo.MOBILE;
        this.debtorId = emhkEddaApplyPo.DEBTORID;
        this.debtorSchemeName = emhkEddaApplyPo.DEBTORIDSCHEMENAME;
        this.currency = emhkEddaApplyPo.CURRENCY;
        this.maximumAmount = emhkEddaApplyPo.MAXIMUMAMOUNT;
        this.frequencyType = emhkEddaApplyPo.FREQUENCYTYPE;
        this.otpNumber = emhkEddaApplyPo.OTPNUMBER;
        this.language = emhkEddaApplyPo.SMSLANG;
        this.note = emhkEddaApplyPo.NOTE;
        this.createdTime = emhkEddaApplyPo.EITIME;
        this.updatedTime = emhkEddaApplyPo.EUTIME;
    }


    public String getEid() {
        return eid;
    }

    public void setEid(String eid) {
        this.eid = eid;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }
    public void status(EddaApplyStatus status) {
        this.status = status.value();
    }

    public String getClientId() {
        return clientId;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public String getBankCode() {
        return bankCode;
    }

    public void setBankCode(String bankCode) {
        this.bankCode = bankCode;
    }

    public String getBankAccount() {
        return bankAccount;
    }

    public void setBankAccount(String bankAccount) {
        this.bankAccount = bankAccount;
    }

    public String getCustomEngName() {
        return customEngName;
    }

    public void setCustomEngName(String customEngName) {
        this.customEngName = customEngName;
    }

    public String getRegisterId() {
        return registerId;
    }

    public void setRegisterId(String registerId) {
        this.registerId = registerId;
    }

    public String getMandateId() {
        return mandateId;
    }

    public void setMandateId(String mandateId) {
        this.mandateId = mandateId;
    }

    public LocalDate getGrantStartDate() {
        return grantStartDate;
    }

    public void setGrantStartDate(LocalDate grantStartDate) {
        this.grantStartDate = grantStartDate;
    }

    public LocalDate getGrantExpiryDate() {
        return grantExpiryDate;
    }

    public void setGrantExpiryDate(LocalDate grantExpiryDate) {
        this.grantExpiryDate = grantExpiryDate;
    }

    public String getCreditReference() {
        return creditReference;
    }

    public void setCreditReference(String creditReference) {
        this.creditReference = creditReference;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = ObjectUtils.isEmpty(mobile) ? null : mobile;
    }

    public String getDebtorId() {
        return debtorId;
    }

    public void setDebtorId(String debtorId) {
        this.debtorId = debtorId;
    }

    public String getDebtorSchemeName() {
        return debtorSchemeName;
    }

    public void setDebtorSchemeName(String debtorSchemeName) {
        this.debtorSchemeName = debtorSchemeName;
    }

    public String getCurrency() {
        return currency;
    }

    public void setCurrency(String currency) {
        this.currency = currency;
    }

    public String getMaximumAmount() {
        return maximumAmount;
    }

    public void setMaximumAmount(String maximumAmount) {
        this.maximumAmount = maximumAmount;
    }

    public String getFrequencyType() {
        return frequencyType;
    }

    public void setFrequencyType(String frequencyType) {
        this.frequencyType = frequencyType;
    }

    public String getOtpNumber() {
        return otpNumber;
    }

    public void setOtpNumber(String otpNumber) {
        this.otpNumber = otpNumber;
    }

    public String getLanguage() {
        return language;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public boolean hasEddi() {
        return note != null && note.startsWith(Constants.EDDI_NOTE_PREFIX);
    }

    public LocalDateTime getCreatedTime() {
        return createdTime;
    }
    public void setCreatedTime(LocalDateTime createdTime) {
        this.createdTime = createdTime;
    }
    public LocalDateTime getUpdatedTime() {
        return updatedTime;
    }
    public void setUpdatedTime(LocalDateTime updatedTime) {
        this.updatedTime = updatedTime;
    }

    public boolean changeStatus(MandateStatus status) {
        EddaApplyStatus applyStatus = status.transferToEddaApplyStatus();
        if(applyStatus == null) {
            return false;
        }
        String oldStatus = this.status;
        this.status = applyStatus.value();
        return !oldStatus.equals(this.status);
    }

    public boolean success() {
        return EddaApplyStatus.SUCCESS.value().equals(this.status);
    }

    public boolean fail() {
        return EddaApplyStatus.FAIL.value().equals(this.status);
    }

    public boolean invalid() {
        return EddaApplyStatus.INVALID.value().equals(this.status);
    }

    public String getRejectReasonCode() {
        return rejectReasonCode;
    }

    public void setRejectReasonCode(String rejectReasonCode) {
        this.rejectReasonCode = rejectReasonCode;
    }
}
